//
//  StockCell.swift
//  SlaughterClient
//
//  Created by zwb on 2023/4/8.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit

class ZyaStockCell: UITableViewCell {
    
    private(set) lazy var container = makeContainer()
    private(set) lazy var headerContainer = makeHeaderContainer()
    private(set) lazy var titleLabel = makeLabel()
    private(set) lazy var subtitleLabel = makeLabel()
    private(set) lazy var describeLabel = makeDescribeLabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        makeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension ZyaStockCell {
    
    private func makeUI() {
        contentView.backgroundColor = UIColor(kshex: "#f3f3f3")
        contentView.addSubview(container)
        container.addSubview(headerContainer)
        headerContainer.addSubview(titleLabel)
        headerContainer.addSubview(subtitleLabel)
        container.addSubview(describeLabel)
        
        container.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5))
            make.height.greaterThanOrEqualTo(60)
        }
        
        headerContainer.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.height.equalTo(30)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(5)
            make.centerY.equalToSuperview()
            make.trailing.equalTo(subtitleLabel.snp.leading)
        }
        
        subtitleLabel.textAlignment = .right
        subtitleLabel.snp.makeConstraints { make in
            make.trailing.equalToSuperview().inset(5)
            make.width.equalTo(100)
            make.centerY.equalToSuperview()
        }
        
        describeLabel.snp.makeConstraints { make in
            make.top.equalTo(headerContainer.snp.bottom).offset(5)
            make.leading.trailing.bottom.equalToSuperview().inset(5)
        }
    }
    
    private func makeHeaderContainer() -> UIView {
        return UIView().then {
            $0.backgroundColor = UIColor(kshex:"#4BC354")
        }
    }
    
    private func makeContainer() -> UIView {
        return UIView().then {
            $0.backgroundColor = UIColor.white
            $0.layer.cornerRadius = 6
            $0.layer.masksToBounds = true
        }
    }
    
    private func makeLabel() -> UILabel {
        return UILabel().then {
            $0.font = UIFont.systemFont(ofSize: 15)
            $0.textColor = .white
        }
    }
    
    private func makeDescribeLabel() -> UILabel {
        return UILabel().then {
            $0.textColor = .darkGray
            $0.font = UIFont.systemFont(ofSize: 14)
            $0.numberOfLines = 0
        }
    }

}
